package ShareYourWay.webpages;

import org.apache.wicket.Session;
import org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;

import ShareYourWay.functions.SignInSession;
import ShareYourWay.util.AuthPage;

/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 * 
 * @see ShareYourWay.project.Start#main(String[])
 */
public class WicketApplication extends WebApplication
{    	
	/**
	 * @see org.apache.wicket.Application#getHomePage()
	 */
	@Override
	public Class<? extends WebPage> getHomePage()
	{
		return HomePage.class;
	
	}

	/**
	 * @see org.apache.wicket.Application#init()
	 */
	@Override
	public void init()
	{
		super.init();
		
		getApplicationSettings().setPageExpiredErrorPage(getHomePage());
		
		getSecuritySettings().setAuthorizationStrategy(
				new SimplePageAuthorizationStrategy( AuthPage.class, HomePage.class) { 
					protected boolean isAuthorized() {
						return ((SignInSession) Session.get()).getUser() != null;
			}
		});
	}
	
	public Session newSession (Request request, Response response) {
		return new SignInSession(request);
	}
}
